package com.smcaiot.jftorg.domain.user;

import cn.hutool.core.util.StrUtil;
import com.smcaiot.core.exception.DomainException;

/**
 * @Author: cz
 * @Date: 2023/9/27
 * @Description:
 */
public enum UserRole {
    JR_ROLE_FJ("100", "辅警"),
    JR_ROLE_MJ("50", "警员"), JR_ROLE_NQ("51", "内勤"), JR_ROLE_SQMJ("52", "社区民警"), JR_ROLE_ZAMJ("53", "治安民警"), JR_ROLE_XZMJ("54", "刑侦民警"),
    JR_ROLE_KSLD("40", "科所队领导"), JR_ROLE_PSLD("41", "派出所所长"), JR_ROLE_PSFLD("42", "派出所副所长"), JR_ROLE_JDLD("43", "教导员"), JR_ROLE_ZHLD("44", "指挥长"),
    JR_ROLE_FJLD("30", "分县局领导");

    private String code;
    private String name;

    UserRole(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static UserRole getByCode(String code) {
        if (StrUtil.isBlank(code)) {
            return null;
        }
        for (UserRole role : UserRole.values()) {
            if (role.getCode().equals(code)) {
                return role;
            }
        }
        return null;
    }

    public boolean isKSLeader() {
        return UserRole.JR_ROLE_KSLD.getCode().equals(getCode()) || UserRole.JR_ROLE_PSLD.getCode().equals(getCode())
                || UserRole.JR_ROLE_PSFLD.getCode().equals(getCode()) || UserRole.JR_ROLE_JDLD.getCode().equals(getCode())
                || UserRole.JR_ROLE_ZHLD.getCode().equals(getCode());
    }

    public boolean isFJLeader() {
        DomainException.isTrue(StrUtil.isNotBlank(getCode()), "角色类型不能为空");
        return UserRole.JR_ROLE_FJLD.getCode().equals(getCode());
    }

    public boolean isPolice() {
        return UserRole.JR_ROLE_MJ.getCode().equals(getCode()) || UserRole.JR_ROLE_NQ.getCode().equals(getCode())
                || UserRole.JR_ROLE_SQMJ.getCode().equals(getCode()) || UserRole.JR_ROLE_ZAMJ.getCode().equals(getCode())
                || UserRole.JR_ROLE_XZMJ.getCode().equals(getCode());
    }

    public boolean isFujing() {
        return UserRole.JR_ROLE_FJ.getCode().equals(getCode());
    }
}
